<!--Copyright (C) Kherty.  All rights reserved.-->
<UserControl x:Class="OpenLS.Spreadsheet.UI.FindAndReplaceControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ss="http://schemas.Kherty.com/office/2007/spreadsheet" 
    xmlns:ssui="clr-namespace:OpenLS.Spreadsheet.UI" 
    xmlns:Internals="clr-namespace:OpenLS.Spreadsheet.UI.Internals" 
    xmlns:uiInternals="clr-namespace:OpenLS.UI.Internals;assembly=OpenLS.UI"
             xmlns:Resources="clr-namespace:OpenLS.Spreadsheet.UI.Internals.Resources"> <!-- loc -->
  <UserControl.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ssui:EnumResources/>
      </ResourceDictionary.MergedDictionaries>
        <ssui:EnumValueEnumerator x:Key="enumEnumerator"/>
    </ResourceDictionary>
  </UserControl.Resources>
  <UserControl.CommandBindings>
    <CommandBinding Command ="{x:Static ApplicationCommands.Close}" Executed="OnClose"/>
  </UserControl.CommandBindings>
    <Border BorderBrush="Black" BorderThickness="1" Background="Beige" CornerRadius="18">
  <Grid Background='{x:Static SystemColors.ControlLightBrush}' >
    <Grid.Resources>
      <Style TargetType='{x:Type ComboBox}'>
        <Setter Property='Height' Value='20'/>
      </Style>
      <ssui:BooleanToVisibilityConverter x:Key='visibilityConverter' VisibilityIfFalse='Hidden'/>
      <ssui:BooleanToVisibilityConverter x:Key='collapseConverter' VisibilityIfFalse='Collapsed'/>
    </Grid.Resources>
    <DockPanel>

      <TabControl Name="tabControl" Margin='5' DockPanel.Dock='Top' SelectionChanged='tabControlSelectionChanged'>

        <TabItem Name="findTabItem" Header="{x:Static uiInternals:UIStringTable.Find_}" >
          <StackPanel Background="{Binding ElementName=findTabItem, Path=Background}">
            <DockPanel>
              <Label DockPanel.Dock='Left' VerticalAlignment='Stretch' Content="{x:Static uiInternals:UIStringTable.FindWhat_}"></Label>
              <Button DockPanel.Dock='Right' Visibility='{Binding ElementName=Options, Path=IsChecked, Converter={StaticResource collapseConverter}}'  Content="{x:Static Resources:UIStringTable.Format_}" ></Button>
              <Label DockPanel.Dock='Right'  Visibility='{Binding ElementName=Options, Path=IsChecked, Converter={StaticResource collapseConverter}}' Content="{x:Static Resources:UIStringTable.NoFormatSet}"></Label>
              <ComboBox Loaded="combo1_Loaded" HorizontalAlignment="Stretch" IsEditable='True' IsReadOnly='False' x:Name='combo1' Text='{Binding ToFind}'
                         SelectedIndex='{Binding ElementName=ToFind, Path=SelectedIndex}'/>
            </DockPanel>
            <DockPanel Visibility='Hidden'>
              <Label DockPanel.Dock='Left' VerticalAlignment='Stretch' Content="{x:Static uiInternals:UIStringTable.ReplaceWith_}"></Label>
              <Button DockPanel.Dock='Right'  Visibility='{Binding ElementName=Options, Path=IsChecked, Converter={StaticResource collapseConverter}}' Content="{x:Static Resources:UIStringTable.Format_}" ></Button>
              <Label DockPanel.Dock='Right'  Visibility='{Binding ElementName=Options, Path=IsChecked, Converter={StaticResource collapseConverter}}' Content="{x:Static Resources:UIStringTable.NoFormatSet}" ></Label>
              <ComboBox  HorizontalAlignment="Stretch" IsEditable='True' IsReadOnly='False' />
            </DockPanel>
            <Grid >
              <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width='*'/>
                <ColumnDefinition/>
              </Grid.ColumnDefinitions>
              <Grid Visibility ='{Binding ElementName=Options, Path=IsChecked, Converter={StaticResource collapseConverter}}'>
                <Grid.RowDefinitions>
                  <RowDefinition/>
                  <RowDefinition/>
                  <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition/>
                  <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Label>Wit_hin:</Label>
                <Label Grid.Row='1'>_Search:</Label>
                <Label Grid.Row='2'>_Look in:</Label>
                <ComboBox Grid.Column='1' SelectedItem ='{Binding Location}'
                          ItemsSource='{Binding Source={x:Type ssui:SearchLocation}, Converter={StaticResource enumEnumerator}}'>
                </ComboBox>
                <ComboBox Grid.Column='1' SelectedItem ='{Binding SearchBy}' Grid.Row='1'
                          ItemsSource='{Binding Source={x:Type ssui:SearchBy}, Converter={StaticResource enumEnumerator}}'>
                </ComboBox>
                <ComboBox Grid.Column='1' Grid.Row='2' SelectedItem='{Binding SearchIn}'
                          ItemsSource='{Binding Source={x:Type ssui:SearchIn}, Converter={StaticResource enumEnumerator}}'>
                </ComboBox>
              </Grid>
              <DockPanel Grid.Column='1' Visibility ='{Binding ElementName=Options, Path=IsChecked, Converter={StaticResource collapseConverter}}'>
                <CheckBox DockPanel.Dock='Top' Margin='4' IsChecked='{Binding MatchCase}' Content="{x:Static Resources:UIStringTable.MatchCase_}"></CheckBox>
                <CheckBox DockPanel.Dock='Top' Margin='4' IsChecked='{Binding MatchEntireCellContent}' Content="{x:Static Resources:UIStringTable.MatchEntireCellContent_}" ></CheckBox>
              </DockPanel>
              <ToggleButton VerticalAlignment='Bottom' Grid.Column='2' IsChecked='{Binding ElementName=Options, Path=IsChecked}'>
                Op_tions
              </ToggleButton>
            </Grid>

          </StackPanel>          
        </TabItem>
        <TabItem Name="replaceTabItem" Header="{x:Static uiInternals:UIStringTable.Replace_}">
          <StackPanel Background="{Binding ElementName=findTabItem, Path=Background}">
            <DockPanel>
              <Label DockPanel.Dock='Left' VerticalAlignment='Stretch'>Fi_nd what:</Label>
              <Button DockPanel.Dock='Right' Visibility='{Binding ElementName=Options, Path=IsChecked, Converter={StaticResource collapseConverter}}' Content="{x:Static Resources:UIStringTable.Format_}" ></Button>
              <Label DockPanel.Dock='Right'  Visibility='{Binding ElementName=Options, Path=IsChecked, Converter={StaticResource collapseConverter}}' Content="{x:Static Resources:UIStringTable.NoFormatSet}" ></Label>
              <ComboBox  HorizontalAlignment="Stretch" Name="ToFind"  IsEditable='True' IsReadOnly='False' Text="{Binding ToFind}" />
            </DockPanel>
            <DockPanel Visibility='{Binding ElementName=replaceTabItem, Path=IsSelected, Converter={StaticResource visibilityConverter}}'>
              <Label DockPanel.Dock='Left' VerticalAlignment='Stretch' Content="{x:Static Resources:UIStringTable.ReplaceWith__}" ></Label>
              <Button DockPanel.Dock='Right'  Visibility='{Binding ElementName=Options, Path=IsChecked, Converter={StaticResource collapseConverter}}' Content="{x:Static Resources:UIStringTable.Format_}" ></Button>
              <Label DockPanel.Dock='Right'  Visibility='{Binding ElementName=Options, Path=IsChecked, Converter={StaticResource collapseConverter}}' Content="{x:Static Resources:UIStringTable.NoFormatSet}" ></Label>
              <ComboBox  HorizontalAlignment="Stretch" IsEditable='True' IsReadOnly='False' Text='{Binding ToReplace}'/>
            </DockPanel>
            <Grid>
              <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width='*'/>
                <ColumnDefinition/>
              </Grid.ColumnDefinitions>
              <Grid Visibility ='{Binding ElementName=Options, Path=IsChecked, Converter={StaticResource collapseConverter}}'>
                <Grid.RowDefinitions>
                  <RowDefinition/>
                  <RowDefinition/>
                  <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition/>
                  <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Label>Wit_hin:</Label>
                <Label Grid.Row='1' Content="{x:Static Resources:UIStringTable.Search__}"></Label>
                <Label Grid.Row='2' Content="{x:Static Resources:UIStringTable.LookIn__}" ></Label>
                <ComboBox Grid.Column='1'  SelectedItem="{Binding Location}"
                          ItemsSource='{Binding Source={x:Type ssui:SearchLocation}, Converter={StaticResource enumEnumerator}}'>
                </ComboBox>
                <ComboBox Grid.Column='1' Name='SearchBy' Grid.Row='1'  SelectedItem='{Binding SearchBy}'
                          ItemsSource='{Binding Source={x:Type ssui:SearchBy}, Converter={StaticResource enumEnumerator}}'>
                </ComboBox>
                <ComboBox Grid.Column='1' Grid.Row='2'  SelectedIndex='0' Text="{x:Static Resources:UIStringTable.Formulas}"></ComboBox>
              </Grid>
              <DockPanel Grid.Column='1' Visibility ='{Binding ElementName=Options, Path=IsChecked, Converter={StaticResource collapseConverter}}'>
                <CheckBox DockPanel.Dock='Top' Margin='4' IsChecked='{Binding MatchCase}' Content="{x:Static Resources:UIStringTable.MatchCase_}"></CheckBox>
                <CheckBox DockPanel.Dock='Top' Margin='4' IsChecked='{Binding MatchEntireCellContent}'  Content="{x:Static Resources:UIStringTable.MatchEntireCellContent_}"></CheckBox>
              </DockPanel>
              <ToggleButton VerticalAlignment='Bottom' Grid.Column='2' Name='Options' Content="{x:Static Resources:UIStringTable.Options_}">
              </ToggleButton>
            </Grid>

          </StackPanel>          
        </TabItem>
      </TabControl>

      <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" DockPanel.Dock='Top'>
        <Button Visibility='{Binding ElementName=replaceTabItem, Path=IsSelected, Converter={StaticResource visibilityConverter}}' Command='{Binding ReplaceAllCommand}'  Content="{x:Static Resources:UIStringTable.ReplaceAll}"></Button>
        <Button Visibility='{Binding ElementName=replaceTabItem, Path=IsSelected, Converter={StaticResource visibilityConverter}}' Command='{Binding ReplaceCommand}' Content="{x:Static Resources:UIStringTable.Replace}"></Button>
        <Button Command="{Binding FindAllCommand}" Content="{x:Static Resources:UIStringTable.FindAll}" IsDefault="False" />
        <Button Command="{Binding FindNextCommand}" Content="{x:Static uiInternals:UIStringTable.FindNext_}" />
        <Button Command="{x:Static ApplicationCommands.Close}" Content="{x:Static Resources:UIStringTable.Close_}"></Button>
      </StackPanel>
      <StatusBar Visibility ="{Binding ElementName=resultView, Path=Visibility}" DockPanel.Dock="Bottom">
        <StatusBarItem >
          <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding Path=MatchingCells.Count}"/>
              <TextBlock Text=" "/>
            <TextBlock Text="{x:Static Resources:UIStringTable.CellsFound}"/>
          </StackPanel>
        </StatusBarItem>
      </StatusBar>
      <ListView SelectionMode="Single" ItemsSource="{Binding MatchingCells}" 
                SelectedItem="{Binding CurrentCell, Mode=TwoWay}">
                <ListView.Style>
                    <Style TargetType="{x:Type ListView}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding MatchingCells}" Value="{x:Null}">
                                <Setter Property="Visibility"  Value="Collapsed"></Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ListView.Style>
                    <ListView.View>
          <GridView>
            <GridViewColumn Header="{x:Static Resources:UIStringTable.Workbook}" Width="100" DisplayMemberBinding="{Binding Path=Worksheet.Workbook.FileName}"/>
            <GridViewColumn Header="{x:Static Resources:UIStringTable.Sheet}" Width="100" DisplayMemberBinding="{Binding Path=Worksheet.Name}"></GridViewColumn>
            <GridViewColumn Header="{x:Static Resources:UIStringTable.Name}" Width="100" DisplayMemberBinding="{Binding Path=Label}"/>
            <GridViewColumn Header="{x:Static Resources:UIStringTable.Cell}" Width="100" DisplayMemberBinding="{Binding Path=Label}"/>
            <GridViewColumn Header="{x:Static Resources:UIStringTable.Value}" Width="100" DisplayMemberBinding="{Binding Path=Value}"/>
            <GridViewColumn Header="{x:Static Resources:UIStringTable.Formula}" Width="100" DisplayMemberBinding="{Binding Path=Formula}"/>
          </GridView>
        </ListView.View>
      </ListView>
    </DockPanel>
    <ResizeGrip HorizontalAlignment ="Right"/>

  </Grid>
    </Border>
</UserControl>
